# -*- coding: utf-8 -*-

import ConfigParser
import os

#-------------project bag---------------

# CurrentPath = os.getcwd()
CurrentPath=os.path.dirname(__file__)

def getConfig(section,key):
	global CurrentPath 
	cf = ConfigParser.ConfigParser()
	path = CurrentPath +'/../etc/config.conf'
	try:
		cf.read(path)
	except:
		print 'error:cannot find config.conf,path:%s' % (str(path))
	sec = cf.sections()
	if not str(section) in sec:
		print 'config.conf has not section named %s' % (section)
	value = cf.get(str(section),str(key))
	return str(value)

def wConfig(section,key,value):
	'''
	增加新的section
	自动设置新的值
	'''
	global CurrentPath
	cf = ConfigParser.ConfigParser()
	cf.read(CurrentPath+'/config.conf')
	sec = cf.sections()
	if not str(section) in sec:
		cf.add_section(str(section))
		print 'succeed to creat a new section'
	cf.set(str(section),str(key),str(value))
	cf.write(open(CurrentPath +'/config.conf','w'))


